package smartbus;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myapplication.Config.OKHttpTool;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.BusdetailBean;

import java.util.stream.Stream;

public class CustomshuttleActivity extends AppCompatActivity {

    private ImageView but_lawyerList;
    private TextView first;
    private TextView end;
    private TextView price;
    private TextView mileage;
    private ImageView left;
    private ImageView right;
    private String customshuttleActivityID;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_customshuttle);
        ivitview();
        //返回
        but_bloak();
        //班车详情
        busdetails();
        //第二步页面：显示日历日期
        revealtime();
    }

    private void revealtime() {
        right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =   new Intent(CustomshuttleActivity.this,RevealtimeActivity.class);
                CustomshuttleActivity.this.startActivity(intent);
            }
        });
    }

    private void busdetails() {
        OKHttpTool.doNetRequest("prod-api/api/bus/line/" + customshuttleActivityID,
                OKHttpTool.GET,
                BusdetailBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                BusdetailBean busdetailBean = (BusdetailBean)obj;
                                BusdetailBean.DataBean data = busdetailBean.getData();
                                if(busdetailBean.getCode()==200){
                                    first.setText(data.getFirst());
                                    end.setText(data.getEnd());
                                    price.setText(String.valueOf(data.getPrice())+"");
                                    mileage.setText(data.getMileage());
                                }
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void but_bloak() {
        but_lawyerList.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CustomshuttleActivity.this.finish();
            }
        });

        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CustomshuttleActivity.this.finish();
            }
        });
    }

    private void ivitview() {
        but_lawyerList = findViewById(R.id.but_lawyerList);
        first = findViewById(R.id.first);
        end = findViewById(R.id.end);
        price = findViewById(R.id.price);
        mileage = findViewById(R.id.mileage);
        left = findViewById(R.id.left);
        right = findViewById(R.id.right);

        Intent intent = getIntent();
        //路线ID
        customshuttleActivityID = intent.getStringExtra("CustomshuttleActivityID");

    }
}